package com.woniu.utils;

import com.woniu.outlet.dao.WorkerPoMapper;
import com.woniu.outlet.po.WorkerPo;
import com.woniu.outlet.po.WorkerPoExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Component
public class GetWorkerId {
    @Autowired
    private WorkerPoMapper workerPoMapper;

    public Integer getWorkerId(HttpServletRequest request){
        String tokenStr = request.getHeader("tokenStr");
        //获取token中的用户名
        String username = JwtTokenUtil.getUserId(tokenStr);

        WorkerPoExample workerPoExample = new WorkerPoExample();
        WorkerPoExample.Criteria criteria = workerPoExample.createCriteria();
        criteria.andAccountEqualTo(username);
        List<WorkerPo> workerPos = workerPoMapper.selectByExample(workerPoExample);

        return Integer.getInteger(workerPos.get(0).getId()+"");
    }
}
